package com.hsgene.util.mq.rocket.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * RocketMQ属性配置
 *
 * @author wangbing
 * @version 1.0
 * @date 2019/1/17 10:01
 * Copyright: Copyright (c) 2019
 */
@Component
@ConfigurationProperties(prefix = "mq.rocket")
public class RocketMQConfigurationProperties {

    /**
     * 消费模式，包括集群模式、广播模式
     */
    private String messageModel;

    /**
     * Producer的标识
     */
    private String producerId;

    /**
     * Consumer的标识
     */
    private String consumerId;
    /**
     * AccessKey, 用于标识、校验用户身份
     */
    private String accessKey;

    /**
     * SecretKey, 用于标识、校验用户身份
     */
    private String secretKey;

    /**
     * 使用STS时，需要配置STS Token, 详情参考https://help.aliyun.com/document_detail/28788.html
     */
    private String securityToken;

    /**
     * 消息发送超时时间，如果服务端在配置的对应时间内未ACK，则发送客户端认为该消息发送失败。
     */
    private String sendMsgTimeoutMillis;

    /**
     * 消息队列服务接入点
     */
    private String onsAddr;

    /**
     * Name Server地址
     */
    private String namsrvAddr;

    /**
     * 消费线程数量
     */
    private String consumeThreadNums;

    /**
     * 设置客户端接入来源，默认ALIYUN
     */
    private String onsChannel;

    /**
     * 消息类型，可配置为NOTIFY、METAQ
     */
    private String mqType;
    /**
     * 是否启动vip channel
     */
    private String isVipChannelEnabled;

    /**
     * 顺序消息消费失败进行重试前的等待时间 单位(毫秒)
     */
    private String suspendTimeMillis;

    /**
     * 消息消费失败时的最大重试次数
     */
    private String maxReconsumeTimes;

    /**
     * 设置每条消息消费的最大超时时间,超过这个时间,这条消息将会被视为消费失败,等下次重新投递再次消费. 每个业务需要设置一个合理的值. 单位(分钟)
     */
    private String consumeTimeout;
    /**
     * 设置事务消息的第一次回查延迟时间
     */
    private String checkImmunityTimeInSeconds;

    /**
     * 是否每次请求都带上最新的订阅关系
     */
    private String postSubscriptionWhenPull;

    /**
     * BatchConsumer每次批量消费的最大消息数量, 默认值为1, 允许自定义范围为[1, 32], 实际消费数量可能小于该值.
     */
    private String consumeMessageBatchMaxSize;

    /**
     * Consumer允许在客户端中缓存的最大消息数量，默认值为5000，设置过大可能会引起客户端OOM，取值范围为[100, 50000]
     * <p>
     * 考虑到批量拉取，实际最大缓存量会少量超过限定值
     * <p>
     * 该限制在客户端级别生效，限定额会平均分配到订阅的Topic上，比如限制为1000条，订阅2个Topic，每个Topic将限制缓存500条
     */
    private String maxCachedMessageAmount;

    /**
     * Consumer允许在客户端中缓存的最大消息容量，默认值为512 MiB，设置过大可能会引起客户端OOM，取值范围为[16, 2048]
     * <p>
     * 考虑到批量拉取，实际最大缓存量会少量超过限定值
     * <p>
     * 该限制在客户端级别生效，限定额会平均分配到订阅的Topic上，比如限制为1000MiB，订阅2个Topic，每个Topic将限制缓存500MiB
     */
    private String maxCachedMessageSizeInMiB;

    /**
     * 设置实例名，注意：如果在一个进程中将多个Producer或者是多个Consumer设置相同的InstanceName，底层会共享连接。
     */
    private String instanceName;

    /**
     * MQ消息轨迹开关
     */
    private String msgTraceSwitch;
    /**
     * Mqtt消息序列ID
     */
    private String mqttMessageId;

    /**
     * Mqtt消息
     */
    private String mqttMessage;

    /**
     * Mqtt消息保留关键字
     */
    private String mqttPublishRetain;

    /**
     * Mqtt消息保留关键字
     */
    private String mqttPublishDubFlag;

    /**
     * Mqtt的二级Topic，是父Topic下的子类
     */
    private String mqttSecondTopic;

    /**
     * Mqtt协议使用的每个客户端的唯一标识
     */
    private String mqttClientId;

    /**
     * Mqtt消息传输的数据可靠性级别
     */
    private String mqttQos;

    /**
     * RocketMQ Topic
     */
    private Map<Object, Object> topic;

    /**
     * RocketMQ Tag
     */
    private Map<Object, Object> tag;

    public Object getTopic(@NotNull Object topicKey) {
        if (CollectionUtils.isEmpty(topic)) {
            return null;
        }
        return topic.get(topicKey);
    }

    public Object getTag(@NotNull Object tagKey) {
        if (CollectionUtils.isEmpty(tag)) {
            return null;
        }
        return tag.get(tagKey);
    }

    public String getMessageModel() {
        return messageModel;
    }

    public void setMessageModel(String messageModel) {
        this.messageModel = messageModel;
    }

    public String getProducerId() {
        return producerId;
    }

    public void setProducerId(String producerId) {
        this.producerId = producerId;
    }

    public String getConsumerId() {
        return consumerId;
    }

    public void setConsumerId(String consumerId) {
        this.consumerId = consumerId;
    }

    public String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public String getSecurityToken() {
        return securityToken;
    }

    public void setSecurityToken(String securityToken) {
        this.securityToken = securityToken;
    }

    public String getSendMsgTimeoutMillis() {
        return sendMsgTimeoutMillis;
    }

    public void setSendMsgTimeoutMillis(String sendMsgTimeoutMillis) {
        this.sendMsgTimeoutMillis = sendMsgTimeoutMillis;
    }

    public String getOnsAddr() {
        return onsAddr;
    }

    public void setOnsAddr(String onsAddr) {
        this.onsAddr = onsAddr;
    }

    public String getNamsrvAddr() {
        return namsrvAddr;
    }

    public void setNamsrvAddr(String namsrvAddr) {
        this.namsrvAddr = namsrvAddr;
    }

    public String getConsumeThreadNums() {
        return consumeThreadNums;
    }

    public void setConsumeThreadNums(String consumeThreadNums) {
        this.consumeThreadNums = consumeThreadNums;
    }

    public String getOnsChannel() {
        return onsChannel;
    }

    public void setOnsChannel(String onsChannel) {
        this.onsChannel = onsChannel;
    }

    public String getMqType() {
        return mqType;
    }

    public void setMqType(String mqType) {
        this.mqType = mqType;
    }

    public String getIsVipChannelEnabled() {
        return isVipChannelEnabled;
    }

    public void setIsVipChannelEnabled(String isVipChannelEnabled) {
        this.isVipChannelEnabled = isVipChannelEnabled;
    }

    public String getSuspendTimeMillis() {
        return suspendTimeMillis;
    }

    public void setSuspendTimeMillis(String suspendTimeMillis) {
        this.suspendTimeMillis = suspendTimeMillis;
    }

    public String getMaxReconsumeTimes() {
        return maxReconsumeTimes;
    }

    public void setMaxReconsumeTimes(String maxReconsumeTimes) {
        this.maxReconsumeTimes = maxReconsumeTimes;
    }

    public String getConsumeTimeout() {
        return consumeTimeout;
    }

    public void setConsumeTimeout(String consumeTimeout) {
        this.consumeTimeout = consumeTimeout;
    }

    public String getCheckImmunityTimeInSeconds() {
        return checkImmunityTimeInSeconds;
    }

    public void setCheckImmunityTimeInSeconds(String checkImmunityTimeInSeconds) {
        this.checkImmunityTimeInSeconds = checkImmunityTimeInSeconds;
    }

    public String getPostSubscriptionWhenPull() {
        return postSubscriptionWhenPull;
    }

    public void setPostSubscriptionWhenPull(String postSubscriptionWhenPull) {
        this.postSubscriptionWhenPull = postSubscriptionWhenPull;
    }

    public String getConsumeMessageBatchMaxSize() {
        return consumeMessageBatchMaxSize;
    }

    public void setConsumeMessageBatchMaxSize(String consumeMessageBatchMaxSize) {
        this.consumeMessageBatchMaxSize = consumeMessageBatchMaxSize;
    }

    public String getMaxCachedMessageAmount() {
        return maxCachedMessageAmount;
    }

    public void setMaxCachedMessageAmount(String maxCachedMessageAmount) {
        this.maxCachedMessageAmount = maxCachedMessageAmount;
    }

    public String getMaxCachedMessageSizeInMiB() {
        return maxCachedMessageSizeInMiB;
    }

    public void setMaxCachedMessageSizeInMiB(String maxCachedMessageSizeInMiB) {
        this.maxCachedMessageSizeInMiB = maxCachedMessageSizeInMiB;
    }

    public String getInstanceName() {
        return instanceName;
    }

    public void setInstanceName(String instanceName) {
        this.instanceName = instanceName;
    }

    public String getMsgTraceSwitch() {
        return msgTraceSwitch;
    }

    public void setMsgTraceSwitch(String msgTraceSwitch) {
        this.msgTraceSwitch = msgTraceSwitch;
    }

    public String getMqttMessageId() {
        return mqttMessageId;
    }

    public void setMqttMessageId(String mqttMessageId) {
        this.mqttMessageId = mqttMessageId;
    }

    public String getMqttMessage() {
        return mqttMessage;
    }

    public void setMqttMessage(String mqttMessage) {
        this.mqttMessage = mqttMessage;
    }

    public String getMqttPublishRetain() {
        return mqttPublishRetain;
    }

    public void setMqttPublishRetain(String mqttPublishRetain) {
        this.mqttPublishRetain = mqttPublishRetain;
    }

    public String getMqttPublishDubFlag() {
        return mqttPublishDubFlag;
    }

    public void setMqttPublishDubFlag(String mqttPublishDubFlag) {
        this.mqttPublishDubFlag = mqttPublishDubFlag;
    }

    public String getMqttSecondTopic() {
        return mqttSecondTopic;
    }

    public void setMqttSecondTopic(String mqttSecondTopic) {
        this.mqttSecondTopic = mqttSecondTopic;
    }

    public String getMqttClientId() {
        return mqttClientId;
    }

    public void setMqttClientId(String mqttClientId) {
        this.mqttClientId = mqttClientId;
    }

    public String getMqttQos() {
        return mqttQos;
    }

    public void setMqttQos(String mqttQos) {
        this.mqttQos = mqttQos;
    }

    public Map<Object, Object> getTopic() {
        return topic;
    }

    public void setTopic(Map<Object, Object> topic) {
        this.topic = topic;
    }

    public Map<Object, Object> getTag() {
        return tag;
    }

    public void setTag(Map<Object, Object> tag) {
        this.tag = tag;
    }
}
